package com.weetop.cfw.base.presenter.imp

import com.weetop.cfw.base.presenter.MinePresenter
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.MineView
import com.weetop.cfw.bean.MyCoursesBean
import com.weetop.cfw.bean.MyLeaseSaleInformationListBean
import com.weetop.cfw.bean.PersonalInfoBean
import com.weetop.cfw.bean.SinglePageIntroduceBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.constants.Constants
import com.weetop.cfw.mine.fragment.MineFragment
import com.weetop.cfw.utils.MMKVUtils
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class MinePresenterImp(var mineView: MineView ?= null):MinePresenter {

    /**
     * 获取个人资料数据
     */
    override fun getPersonalInfoData(mineFragment: MineFragment) {
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().getPersonalInfo(),mineFragment,object:
            RxJavaCallBack<PersonalInfoBean>(){
            override fun onSuccess(t: PersonalInfoBean?) {
                mineView?.personalInfoGetSuccess(t)
            }

            override fun onRequestError(t: PersonalInfoBean?) {
                super.onRequestError(t)
                mineView?.showNativeShortToast(t?.message)
                mineFragment.dismissLoadingDialog()
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
                mineFragment.dismissLoadingDialog()
            }
        })
    }

    /**
     * 获取待审核出租出售信息
     */
    override fun toBeAuditedLeaseSaleInformationList(mineFragment: MineFragment) {
        val queryMap = HashMap<String,String>()
        queryMap["siteid"] = Constants.siteId.toString()
        queryMap["Token"] = MMKVUtils.getToken()
        queryMap["Status"] = "1"
        queryMap["Curpage"] = "1"
        queryMap["Pagesize"] = "10"
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().getMyRentalSaleListData(queryMap),mineFragment,object:RxJavaCallBack<MyLeaseSaleInformationListBean>(){
            override fun onSuccess(t: MyLeaseSaleInformationListBean?) {
                mineView?.toBeAuditedLeaseSaleInformationGetSuccess(t)
            }
        })
    }

    /**
     * 获取已发布出租出售信息
     */
    override fun publishedSaleInformationList(mineFragment: MineFragment) {
        val queryMap = HashMap<String,String>()
        queryMap["siteid"] = Constants.siteId.toString()
        queryMap["Token"] = MMKVUtils.getToken()
        queryMap["Status"] = "0"
        queryMap["Curpage"] = "1"
        queryMap["Pagesize"] = "10"
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().getMyRentalSaleListData(queryMap),mineFragment,object:RxJavaCallBack<MyLeaseSaleInformationListBean>(){
            override fun onSuccess(t: MyLeaseSaleInformationListBean?) {
                mineView?.publishedSaleInformationGetSuccess(t)
            }
        })
    }

    /**
     * 获取常见问题富文本
     */
    override fun getCommonProblemData(mineFragment: MineFragment) {
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().getAppRelativeSinglePageIntroduce("appqs"),mineFragment,object:RxJavaCallBack<SinglePageIntroduceBean>(){

            override fun onSuccess(t: SinglePageIntroduceBean?) {
                mineView?.commonProblemDataGetSuccess(t)
            }

        })
    }

    /**
     * 获取服务保障富文本
     */
    override fun getServiceGuaranteeData(mineFragment: MineFragment) {
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().getAppRelativeSinglePageIntroduce("appserv"),mineFragment,object:RxJavaCallBack<SinglePageIntroduceBean>(){

            override fun onSuccess(t: SinglePageIntroduceBean?) {
                mineView?.serviceGuaranteeGetSuccess(t)
            }
        })
    }

    /**
     * 获取用户协议富文本
     */
    override fun getUserAgreementData(mineFragment: MineFragment) {
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().getAppRelativeSinglePageIntroduce("appagree"),mineFragment,object:RxJavaCallBack<SinglePageIntroduceBean>(){

            override fun onSuccess(t: SinglePageIntroduceBean?) {
                mineView?.userAgreementDataGetSuccess(t)
            }
        })
    }




    /**
     * 获取我的课程列表
     */
    override fun getMyCourseList(mineFragment: MineFragment) {
        RxJavaUtils.useInSupportFragmentOnDestoryView(RetrofitUtils.getApi().getMyCoursesList(status = 1,curpage = 1,pagesize = 10),mineFragment,object:RxJavaCallBack<MyCoursesBean>(){
            override fun onSuccess(t: MyCoursesBean?) {
                mineView?.courseListGetSuccess(t)
            }
        })
    }

    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        mineView = baseView as? MineView
    }

    /**
     * 解绑
     */
    override fun detachView() {
       mineView = null
    }
}